<?php
if($_POST['act']=='sendmail'){
    if($_POST['action']){
        $db->query("update ".MEMBEOPINIONS." set status='1',reply_time='".date('Y-m-d H:i:s',time())."' where id='$_POST[id]'");
        echo send_mail($_POST["email"],$_POST["name"],$_POST["title"],nl2br($_POST["content"]));
        admin_msg("module.php?m=member&s=memberopinions.php",'发送成功');
    }
}
if($_GET['act']=='reply_now' && $_GET['id']>0){
    $sql = "select id,contact,opinion_content from ".MEMBEOPINIONS." where id=".$_GET['id'];
    $db->query($sql);
    $de['opinion_info'] = $db->fetchRow();
}elseif($_GET['act']=='disable_opinion' && $_GET['id']>0){
    $sql = "update ".MEMBEOPINIONS." set status='-1' where id=".$_GET['id'];
    $db->query($sql);
    msg('?m=member&s=memberopinions.php');
}elseif($_GET['act']=='applied_opinion' && $_GET['id']>0){
	$sql = "update ".MEMBEOPINIONS." set status='1' where id=".$_GET['id'];
	$db->query($sql);
	msg('?m=member&s=memberopinions.php');
}else{
    $where = "";
    $order = "";
    $timeorder = "";
    if($_GET['sdate']!='' && $_GET['edate']!='' && (strtotime($_GET['sdate'])<=strtotime($_GET['edate']))){
        $where .=" and a.create_time>='".$_GET['sdate']."' and a.create_time<='".$_GET['edate']."'";
    }else{
        if($_GET['sdate']!='' && $_GET['edate']==''){
            $where .=" and a.create_time>='".$_GET['sdate']."'";
        }
        if($_GET['sdate']=='' && $_GET['edate']!=''){
            $where .=" and a.create_time<='".$_GET['edate']."'";
        }
    }
    if($_GET['username']!=''){
        $where .=" and b.username like '$_GET[username]%'";
    }
    if($_GET['opinion_type']!="10" && $_GET['opinion_type']!=""){
        $where .=" and a.opinion_type='$_GET[opinion_type]'";
    }
    if($_GET['status']!="10" && $_GET['status']!=""){
        $where .=" and a.status='$_GET[status]'";
    }
    if($_GET['ctimeorder']=='asc'){
        $timeorder = "create_time asc";
    }else{
        if(!empty($_GET['ctimeorder'])){
            $timeorder = "create_time desc";
        }else{
            if($_GET['rtimeorder']=='asc'){
                $timeorder = "reply_time asc";
            }else{
                if(!empty($_GET['rtimeorder'])){
                    $timeorder = "reply_time desc";
                }else{
                    $timeorder = "create_time desc";
                }
            }
        }
    }
    
    $sql = "select a.*,b.username from ".MEMBEOPINIONS." a left join ".MEMBER." b on a.member_id=b.userid where 1".$where." order by ".$timeorder;
    
    include_once("../includes/page_utf_class.php");
    $page = new Page;
    $page->listRows=20;
    $db->query($sql);
    $totalRows = $db->num_rows();
    if (!$page->__get('totalRows')){
        $db->query($sql);
        $page->totalRows = $db->num_rows();
    }
    $sql .= "  limit ".$page->firstRow.",".$page->listRows;
    
    $db->query($sql);
    $totalRows = $db->num_rows();
    if (!$page->__get('totalRows')){
        $db->query($sql);
        $page->totalRows = $db->num_rows();
    }
    $de['page'] = $page->prompt();
    $de['list']=$db->getRows();
    $db->query("select id,type_name from ".MEMBEOPINIONSTYPE." where status='1' order by display_order asc");
    $opinion_type = $db->getRows();
    $opinion_type_n = array();
    foreach ($opinion_type as $otv)
    {
        $opinion_type_n[$otv['id']] = $otv['type_name'];
    }
    $de['opinion_type'] = $opinion_type_n;
}


$tpl->assign('countpro',$totalRows);
$tpl->assign('de',$de);
$tpl->display('memberopinions.htm');
?>